import request from '@/utils/request'

/**
 * 教师管理API服务
 */

/**
 * 获取教师分页列表
 * @param {Object} params 查询参数
 * @param {number} params.page 页码
 * @param {number} params.size 每页条数
 * @param {string} params.keyword 搜索关键词
 * @returns {Promise} 返回教师分页数据
 */
export const getTeacherPage = (params) => {
  return request({
    url: '/api/edu/teacher/page',
    method: 'post',
    data: params
  })
}

/**
 * 获取所有教师列表
 * @returns {Promise} 返回教师列表
 */
export const getTeacherList = () => {
  return request({
    url: '/api/edu/teacher/list',
    method: 'get'
  })
}

/**
 * 根据ID获取教师详情
 * @param {string} id 教师ID
 * @returns {Promise} 返回教师详情
 */
export const getTeacherById = (id) => {
  return request({
    url: '/api/edu/teacher/' + id,
    method: 'get'
  })
}

/**
 * 添加或更新教师
 * @param {Object} teacherData 教师数据
 * @returns {Promise} 返回操作结果
 */
export const saveOrUpdateTeacher = (teacherData) => {
  if (teacherData.id) {
    return request({
      url: '/api/edu/teacher',
      method: 'put',
      data: teacherData
    })
  } else {
    return request({
      url: '/api/edu/teacher',
      method: 'post',
      data: teacherData
    })
  }
}

/**
 * 删除教师
 * @param {string} id 教师ID
 * @returns {Promise} 返回操作结果
 */
export const deleteTeacher = (id) => {
  return request({
    url: '/api/edu/teacher/' + id,
    method: 'delete'
  })
}

export default {
  getTeacherPage,
  getTeacherList,
  getTeacherById,
  saveOrUpdateTeacher,
  deleteTeacher
}